package com.pengweiwei.androidzygote.goods;

import android.os.Bundle;
import androidx.recyclerview.widget.RecyclerView;

import com.android.volley.Request;
import com.putong35.common.app.ui.AppListFragment;
import com.putong35.common.baseactfrag.adapter.DataBindRecyclerViewAdapter;
import com.putong35.common.baseactfrag.adapter.DataBindViewHolder;
import com.putong35.common.baseactfrag.adapter.RecyclerViewBaseAdapter;
import com.putong35.common.httprequest.UrlParams;
import com.putong35.common.httprequest.responsecallbacks.ListBeanResponseListener;
import com.putong35.common.httprequest.responsecallbacks.ListBeanResponseListenerImpl;
import com.putong35.easyui.picture.browser.constant.Constant;
import com.putong35.easyui.picture.browser.view.PictureBrowserActivity;
import com.pengweiwei.androidzygote.BR;
import com.pengweiwei.androidzygote.R;
import com.pengweiwei.androidzygote.main.UrlCenter;

import java.util.ArrayList;


/**
 * 商品评论列表
 */
public class CommentListFragment extends AppListFragment {

    public static final String KEY_GOODS_BEAN = "goodsBean";
    private GoodsBean goodsBean;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        goodsBean = (GoodsBean) getArguments().getSerializable(KEY_GOODS_BEAN);
        super.onCreate(savedInstanceState);
        setRequestInfo(Request.Method.GET, UrlCenter.GOODS_COMMENT);
    }


    @Override
    public RecyclerViewBaseAdapter createAdapter() {
        return new DataBindRecyclerViewAdapter<CommentBean>(getActivity(), R.layout.listitem_goods_comment, BR.itemBean) {
            @Override
            public void onBindHolder(RecyclerView.ViewHolder viewHolder, int dataPosition) {
                CommentBean bean = getData().get(dataPosition);
                DataBindViewHolder holder = (DataBindViewHolder) viewHolder;
                holder.getBinding().getRoot().findViewById(R.id.lytImages).setOnClickListener(v -> {
                    ArrayList<String> list = new ArrayList<>();
                    list.addAll(bean.getImages());
                    PictureBrowserActivity.watchPhoto(getActivity(), list, Constant.RESULT_CODE_SELETE);
                });

                super.onBindHolder(viewHolder, dataPosition);
            }
        };
    }


    @Override
    public ListBeanResponseListener makeResponseListener() {
        return new ListBeanResponseListenerImpl<>(CommentBean.class, this);
    }


    @Override
    public UrlParams makeParams() {
        UrlParams urlParams = super.makeParams();
        urlParams.put("goods_id", goodsBean.getGoods_id());
        return urlParams;
    }


}
